import pymysql as db

conn = db.connect (host = "localhost",
            user = "student",
            passwd = "anything",
            db = "emanuelacademy")
cursor = conn.cursor()


def getAnswer(uniqueID):
    cursor.execute("SELECT answer, questionType FROM answers WHERE questionID = '%d'" %uniqueID)
    row = cursor.fetchone()
    cursor.execute("DELETE FROM answers WHERE questionID = '%d'" %uniqueID)
    conn.commit()
    if row is not None:
        return row[0], row[1]
    else:
        return None


def storeAnswer(id, answer, problemType):
	
    uniqueID = id
    questionAnswer = answer


    cursor.execute('''INSERT INTO answers (questionID, questionType, answer)
                   VALUES ('%d', '%s', '%d')
                   ''' %(uniqueID, problemType, questionAnswer))
    conn.commit()
